package com.kingdee.eas.custom.aoyuan.aytime.bizbill.web;

import java.math.BigDecimal;
import java.sql.SQLException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

import javax.faces.context.FacesContext;
import javax.faces.event.AbortProcessingException;
import javax.servlet.ServletRequest;

import org.apache.commons.lang.StringUtils;
import org.operamasks.faces.annotation.Accessible;
import org.operamasks.faces.annotation.Action;
import org.operamasks.faces.annotation.Bind;
import org.operamasks.faces.annotation.Inject;
import org.operamasks.faces.annotation.ManagedBean;
import org.operamasks.faces.annotation.ManagedBeanScope;
import org.operamasks.faces.component.action.ActionEvent;
import org.operamasks.faces.component.ajax.AjaxUpdater;
import org.operamasks.faces.component.form.impl.UIDateField;
import org.operamasks.faces.component.widget.UIButton;

import com.kingdee.bos.BOSException;
import com.kingdee.bos.Context;
import com.kingdee.bos.dao.ormapping.ObjectUuidPK;
import com.kingdee.bos.dao.query.IQueryExecutor;
import com.kingdee.bos.dao.query.QueryExecutorFactory;
import com.kingdee.bos.metadata.MetaDataPK;
import com.kingdee.bos.metadata.entity.EntityViewInfo;
import com.kingdee.bos.metadata.entity.FilterInfo;
import com.kingdee.bos.metadata.entity.FilterItemInfo;
import com.kingdee.bos.metadata.entity.SelectorItemCollection;
import com.kingdee.bos.metadata.entity.SelectorItemInfo;
import com.kingdee.bos.metadata.query.util.CompareType;
import com.kingdee.bos.util.BOSUuid;
import com.kingdee.bos.waf.action.AbstractWebAction;
import com.kingdee.bos.waf.annotation.IBOSBizCtrl;
import com.kingdee.bos.waf.ctx.WafContext;
import com.kingdee.bos.waf.util.OperateState;
import com.kingdee.bos.waf.winlet.BaseBean;
import com.kingdee.bos.web.components.widget.impl.UIPromptBox;
import com.kingdee.eas.framework.ICoreBase;
import com.kingdee.eas.framework.ObjectBaseInfo;
import com.kingdee.eas.hr.emp.PersonPositionCollection;
import com.kingdee.eas.hr.emp.PersonPositionFactory;
import com.kingdee.eas.hr.emp.PersonPositionInfo;
import com.kingdee.eas.util.app.ContextUtil;
import com.kingdee.eas.util.app.DbUtil;

import com.kingdee.eas.basedata.org.AdminOrgUnitInfo;
import com.kingdee.eas.basedata.org.FullOrgUnitInfo;
import com.kingdee.eas.basedata.org.HROrgUnitInfo;
import com.kingdee.eas.basedata.org.PositionFactory;
import com.kingdee.eas.basedata.org.PositionInfo;
import com.kingdee.eas.basedata.org.PositionMemberCollection;
import com.kingdee.eas.basedata.org.PositionMemberFactory;
import com.kingdee.eas.basedata.person.PersonFactory;
import com.kingdee.eas.basedata.person.PersonInfo;
import com.kingdee.eas.common.EASBizException;
import com.kingdee.eas.custom.aoyuan.aytime.AYAttenBillStatusEnum;
import com.kingdee.eas.custom.aoyuan.aytime.HolidayTypeEnum;
import com.kingdee.eas.custom.aoyuan.aytime.TimeCardTypeEnum;
import com.kingdee.eas.custom.aoyuan.aytime.basedata.BasesettingCollection;
import com.kingdee.eas.custom.aoyuan.aytime.basedata.BasesettingFactory;
import com.kingdee.eas.custom.aoyuan.aytime.basedata.BasesettingInfo;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.CardRecordFactory;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.CardRecordInfo;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.HolidayBillEntryFactory;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.HolidayBillFactory;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.IHolidayBill;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.HolidayBillInfo;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.HolidayBillEntryInfo;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.HolidayBillEntryCollection;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.PersonOTBalanceCollection;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.PersonOTBalanceFactory;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.PersonOTBalanceInfo;
import com.kingdee.eas.custom.aoyuan.aytime.bizbill.web.AbstractAttenDetailListUIBean.ActionQueryData;
import com.kingdee.jdbc.rowset.IRowSet;

@ManagedBean(name = "custom.aoyuan.aytime.bizbill.HolidayBillEditUIBean", scope = ManagedBeanScope.SESSION)
public class HolidayBillEditUIBean extends AbstractHolidayBillEditUIBean {

	@Bind
	public String bthAttach_Rendered = "true";
	
	@Bind(id = "prmtDept")
	private UIPromptBox prmtDept;

	@Bind(id = "txtBizDate")
	private UIDateField bizDate_label;

	@Bind(id = "prmtDept")
	private UIPromptBox prmtdept;

	@Bind(id = "prmtapplier")
	private UIPromptBox prmtEmp;

	@Bind(id = "prmtposition")
	private UIPromptBox prmtposition;

	@Bind(id = "txtStartdate")
	private UIDateField txtStartdate;

	@Bind(id = "txtendDate")
	private UIDateField txtendDate;
	
	@Bind
    public AjaxUpdater otBalanceUpdater;
	
	@Bind
	private PersonOTBalanceInfo otBalanceInfo;
	
	@Bind
	private BasesettingInfo baseSetInfo;
	
	//年假
	@Bind
	private BigDecimal annualHoliday=new BigDecimal("0");
	
	//默认年假
	@Bind
	private BigDecimal totalAnnualHoliday=new BigDecimal("5");
	
	//默认不可调休，1为调休
	@Bind
	private Integer isOtNegative=0;

	@Bind
	private UIButton btnMySumit;

	@Bind
	private UIButton btnMySave;

	public void beforeRender(boolean isPostBack) {
		FacesContext ctx = FacesContext.getCurrentInstance();
		ServletRequest request = (ServletRequest) ctx.getExternalContext()
				.getRequest();
		String fromBill = request.getParameter("fromBill");
		if (StringUtils.isNotEmpty(fromBill)) {
			String billId = request.getParameter("billId");
			if(StringUtils.isNotEmpty(billId))
			{
				try {
					ICoreBase biz = getBizInterface();
					SelectorItemCollection seletor = this.getSelectors();
					Object newModel = biz.getValue(new ObjectUuidPK(billId),
							seletor);
					this.setModel((ObjectBaseInfo) newModel);
				} catch (EASBizException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (BOSException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}				
			}
		}
		super.beforeRender(isPostBack);
	}

	public void pageOnload() {
		super.pageOnload();
		
		HolidayBillInfo modelInfo = (HolidayBillInfo) this.model;
		FacesContext ctx = FacesContext.getCurrentInstance();
		ServletRequest request = (ServletRequest) ctx.getExternalContext()
				.getRequest();

		if (OperateState.ADDNEW.equals(getOperateState())) {
			bizDate_label.setValue(new Date());
			PersonInfo personInfo = ContextUtil.getCurrentUserInfo(
					WafContext.getInstance().getContext()).getPerson();
			newInitF7(personInfo);
		} else if (AYAttenBillStatusEnum.DRAFT.equals(modelInfo.getStatus())) {
			initDeptF7();
			if(OperateState.VIEW.equals(getOperateState()))
			{
				operateState = OperateState.VIEW;	
				btnMySave.setRendered(false);
				btnMySumit.setRendered(false);
			}else
			{
				operateState = OperateState.EDIT;				
			}
		}else if(AYAttenBillStatusEnum.AUDIT_FAIL.equals(modelInfo.getStatus())){
			initDeptF7();
			if(OperateState.VIEW.equals(getOperateState()))
			{
				operateState = OperateState.VIEW;	
				btnMySave.setRendered(false);
				btnMySumit.setRendered(false);
			}else
			{
				operateState = OperateState.EDIT;				
			}
			//this.outerScript="alert('该单据已经提交，只能查看!');";
		}else if(AYAttenBillStatusEnum.SUBMIT.equals(modelInfo.getStatus())){
			initDeptF7();
			operateState = OperateState.VIEW;	
			btnMySave.setRendered(false);
			btnMySumit.setRendered(false);
			String billId = request.getParameter("billId");
			if(StringUtils.isEmpty(billId))
			{
				//this.outerScript="alert('该单据已经提交，只能查看!');";				
			}
		}else {
			initDeptF7();
			operateState = OperateState.VIEW;
			btnMySave.setRendered(false);
			btnMySumit.setRendered(false);
			this.outerScript="alert('该单据已经提交，只能查看!');";
		}
		otBalanceInfo=getPersonOTBalanceInfo();
		annualHoliday=getAnnualHoliday();
		baseSetInfo=getBasesetting();
		setAnnualHolidayAndOtNegative(baseSetInfo);
	}
	
	private void setAnnualHolidayAndOtNegative(BasesettingInfo baseSetInfo)
	{
		if(baseSetInfo!=null)
		{
			if(baseSetInfo.getAnnual()!=null)
			{
				totalAnnualHoliday=baseSetInfo.getAnnual();
			}
			if(baseSetInfo.isOtNegative())
			{
				isOtNegative=1;
			}else
			{
				//不可加班透支
				isOtNegative=0;
			}
		}		
	}
	
	
	private BasesettingInfo getBasesetting()
	{
		String value = (String) prmtEmp.getSubmittedValue();
		PersonInfo personInfo = new PersonInfo();
		HolidayBillInfo modelInfo = (HolidayBillInfo) this.model;
		if(StringUtils.isEmpty(value))
		{
		    personInfo=(PersonInfo)prmtEmp.getValue();
			if(personInfo!=null)
			{
				value=personInfo.getId().toString();
			}
		}
		if(StringUtils.isNotEmpty(value))
		{
			personInfo.setId(BOSUuid.read(value));
		}else
		{
			
			if(modelInfo.getApplier()!=null)
			{
				personInfo=modelInfo.getApplier();
			}else
			{
				 personInfo = ContextUtil.getCurrentUserInfo(
						WafContext.getInstance().getContext()).getPerson();
			}
		}
		HROrgUnitInfo hrOrg=new HROrgUnitInfo();
		if(modelInfo.getHROrgUnit()!=null)
		{
			hrOrg=modelInfo.getHROrgUnit();
		}else
		{
			PositionInfo positionInfo = getPosition(personInfo);
			hrOrg=positionInfo.getHrOrgUnit();
			modelInfo.setHROrgUnit(positionInfo.getHrOrgUnit());
		}
		if(hrOrg.getId()!=null)
		{
			EntityViewInfo evi = new EntityViewInfo();
			FilterInfo filter = new FilterInfo();
			filter.getFilterItems().add(
					new FilterItemInfo("HROrgUnit.id", hrOrg.getId().toString(), CompareType.EQUALS));
			evi.setFilter(filter);
			SelectorItemCollection sic = super.getSelectors();
			sic.add(new SelectorItemInfo("id"));
			sic.add(new SelectorItemInfo("*"));
			evi.setSelector(sic);
			try {
				BasesettingCollection coll=BasesettingFactory.getRemoteInstance().getBasesettingCollection(evi);
				if(coll.size()>0)
				{
					return coll.get(0);
				}
			} catch (BOSException e) {
				e.printStackTrace();
			}			
		}
		return null;
	}
	
	//获取已经使用的年假
	private BigDecimal getAnnualHoliday()
	{
		BigDecimal useInt=new BigDecimal("0");
		String value = (String) prmtEmp.getSubmittedValue();
		PersonInfo personInfo = new PersonInfo();
		if(StringUtils.isEmpty(value))
		{
		    personInfo=(PersonInfo)prmtEmp.getValue();
			if(personInfo!=null)
			{
				value=personInfo.getId().toString();
			}
		}
		try {
			if(StringUtils.isNotEmpty(value))
			{
				personInfo.setId(BOSUuid.read(value));
				useInt=sumAnnualHoliday(personInfo);
			}else
			{
				HolidayBillInfo modelInfo = (HolidayBillInfo) this.model;
				
				if(modelInfo.getApplier()!=null)
				{
					personInfo=modelInfo.getApplier();
				}else
				{
					 personInfo = ContextUtil.getCurrentUserInfo(
							WafContext.getInstance().getContext()).getPerson();
				}
				useInt=sumAnnualHoliday(personInfo);
			}
		} catch (BOSException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		if(useInt.compareTo(new BigDecimal("0"))>0)
		{
			useInt=useInt.divide(new BigDecimal("7.5"),2, BigDecimal.ROUND_HALF_EVEN);		
		}
		return useInt;
	}
	
	private BigDecimal sumAnnualHoliday(PersonInfo personInfo) throws BOSException
	{
		BigDecimal useInt=new BigDecimal("0");
		//当年1月1日，到12月31日
	 	Calendar c = Calendar.getInstance();
	    c.setTime(new Date());
	    c.set(Calendar.HOUR, 0);
	    c.set(Calendar.MINUTE, 0);
	    c.set(Calendar.SECOND, 0);
	    c.set(Calendar.MONTH,0);
	    c.set(Calendar.DATE,1);
	    Date startDate = c.getTime();
	    c.setTime(new Date());
	    c.set(Calendar.HOUR, 23);
	    c.set(Calendar.MINUTE, 59);
	    c.set(Calendar.SECOND, 59);
	    c.set(Calendar.MONTH,12);
	    c.set(Calendar.DATE,-1);
	   Date endDate = c.getTime();
		EntityViewInfo evi = new EntityViewInfo();
		FilterInfo filter = new FilterInfo();
		if (personInfo != null) {
			filter.getFilterItems().add(
					new FilterItemInfo("parent.applier.id", personInfo
							.getId().toString(), CompareType.EQUALS));
			filter.getFilterItems().add(
					new FilterItemInfo("parent.status", AYAttenBillStatusEnum.PASS, CompareType.EQUALS));
			filter.getFilterItems().add(
					new FilterItemInfo("holidayType.htype", HolidayTypeEnum.WINTER, CompareType.EQUALS));
			filter.getFilterItems().add(new FilterItemInfo("bizDate",startDate,CompareType.GREATER_EQUALS));
			filter.getFilterItems().add(new FilterItemInfo("bizDate",endDate,CompareType.LESS_EQUALS));	 
		} else {
			return useInt;
		}
		evi.setFilter(filter);
		HolidayBillEntryCollection  col=HolidayBillEntryFactory.getRemoteInstance().getHolidayBillEntryCollection(evi);
		if(col.size()>0)
		{
			for(int i=0;i<col.size();i++)
			{
				HolidayBillEntryInfo entry=col.get(i);
				useInt=useInt.add(entry.getTotalhour());
			}
		}
		return useInt;
	}
	
	private PersonOTBalanceInfo getPersonOTBalanceInfo()
	{
		String value = (String) prmtEmp.getSubmittedValue();
		if(StringUtils.isEmpty(value))
		{
			PersonInfo personInfo=(PersonInfo)prmtEmp.getValue();
			if(personInfo!=null)
			{
				value=personInfo.getId().toString();
			}
		}
		
		PersonOTBalanceInfo oTBalanceInfo = null;
		PersonOTBalanceCollection cos=null;
		if(StringUtils.isNotEmpty(value))
		{
			PersonInfo personInfo = new PersonInfo();
			personInfo.setId(BOSUuid.read(value));
			cos = getPersonOTBalanceCollection(personInfo);
		}else
		{
			HolidayBillInfo modelInfo = (HolidayBillInfo) this.model;
			PersonInfo personInfo = new PersonInfo();
			if(modelInfo.getApplier()!=null)
			{
				personInfo=modelInfo.getApplier();
			}else
			{
				 personInfo = ContextUtil.getCurrentUserInfo(
						WafContext.getInstance().getContext()).getPerson();
			}

			cos = getPersonOTBalanceCollection(personInfo);
		}
		if (cos != null) {
			if (cos.size() > 0) {
				// 已经存在记录，不创建
				oTBalanceInfo = cos.get(0);
			} else {
				// 新增员工调休记录
				oTBalanceInfo = new PersonOTBalanceInfo();
				oTBalanceInfo.setNormalOT(new BigDecimal("0"));
				oTBalanceInfo.setWeekenOT(new BigDecimal("0"));
				oTBalanceInfo.setHolidayOT(new BigDecimal("0"));
				oTBalanceInfo.setTotaluse(new BigDecimal("0"));
			}
		}else
		{
			// 新增员工调休记录
			oTBalanceInfo = new PersonOTBalanceInfo();
			oTBalanceInfo.setNormalOT(new BigDecimal("0"));
			oTBalanceInfo.setWeekenOT(new BigDecimal("0"));
			oTBalanceInfo.setHolidayOT(new BigDecimal("0"));
			oTBalanceInfo.setTotaluse(new BigDecimal("0"));			
		}			

		return oTBalanceInfo;
	}

	public SelectorItemCollection getSelectors() {
		SelectorItemCollection sic = super.getSelectors();
		sic.add(new SelectorItemInfo("id"));
		sic.add(new SelectorItemInfo("*"));
		sic.add(new SelectorItemInfo("creator.*"));
		sic.add(new SelectorItemInfo("entrys.id"));
		sic.add(new SelectorItemInfo("entrys.*"));
		return sic;
	}

	@Action(immediate = true)
	public void changeEmp() {
		String value = (String) prmtEmp.getSubmittedValue();
		// newInitF7((PersonInfo)value);
		PersonInfo personInfo = new PersonInfo();
		personInfo.setId(BOSUuid.read(value));
		PositionInfo positionInfo = getPosition(personInfo);
		HolidayBillInfo modelInfo = (HolidayBillInfo) this.model;
		modelInfo.setHROrgUnit(positionInfo.getHrOrgUnit());

		modelInfo.setDept(positionInfo.getAdminOrgUnit());
		modelInfo.setPosition(positionInfo);
		prmtposition.setValue(positionInfo);
		prmtposition.setSubmittedValue(positionInfo);
		prmtposition.repaint();
		otBalanceInfo=getPersonOTBalanceInfo();
		annualHoliday=getAnnualHoliday();
		setAnnualHolidayAndOtNegative(baseSetInfo);
		otBalanceUpdater.reload();

		if (positionInfo.getAdminOrgUnit() != null) {
			prmtdept.setValue(positionInfo.getAdminOrgUnit());
			prmtdept.setSubmittedValue(positionInfo.getAdminOrgUnit());
			prmtdept.repaint();
		}

	}

	private void newInitF7(PersonInfo personInfo) {
		prmtEmp.setValue(personInfo);
		prmtEmp.setSubmittedValue(personInfo.getId().toString());
		PositionInfo positionInfo = getPosition(personInfo);
		HolidayBillInfo modelInfo = (HolidayBillInfo) this.model;
		modelInfo.setHROrgUnit(positionInfo.getHrOrgUnit());
		
		prmtposition.setValue(positionInfo);
		prmtposition.setSubmittedValue(positionInfo);

		if (positionInfo.getAdminOrgUnit() != null) {
			modelInfo.setDept(positionInfo.getAdminOrgUnit());
			prmtdept.setValue(positionInfo.getAdminOrgUnit());
			prmtdept.setSubmittedValue(positionInfo.getAdminOrgUnit());
		}
	}

	private PositionInfo getPosition(PersonInfo personInfo) {
		PositionInfo positionInfo = null;
		EntityViewInfo entityViewInfo = new EntityViewInfo();
		FilterInfo filterInfo = new FilterInfo();
		filterInfo.getFilterItems().add(
				new FilterItemInfo("person.id", personInfo.getId(),
						CompareType.EQUALS));
		entityViewInfo.setFilter(filterInfo);
		IQueryExecutor iqec = QueryExecutorFactory.getRemoteInstance(new MetaDataPK(    
                "com.kingdee.eas.custom.aoyuan.aytime.basedata.app",    
                "PersonHRQuery"));
		try {
			iqec.setObjectView(entityViewInfo);  
			IRowSet irow = iqec.executeQuery();
			if(irow.size()>0)
			{
				if(irow.next())
				{
					 positionInfo=new PositionInfo();
					 HROrgUnitInfo hrOrg=new HROrgUnitInfo();
					 AdminOrgUnitInfo adminOrg=new AdminOrgUnitInfo();
					 String positionId=irow.getString("Position.id");
					 String positionName=irow.getString("Position.name");
					 positionInfo.setId(BOSUuid.read(positionId));
					 positionInfo.setName(positionName);
					 String hrOrgId=irow.getString("HROrgUnit.id");
					 String hrOrgName=irow.getString("HROrgUnit.name");
					 hrOrg.setId(BOSUuid.read(hrOrgId));
					 hrOrg.setName(hrOrgName);
					 String adminOrgId=irow.getString("AdminOrgUnit.id");
					 String adminOrgName=irow.getString("AdminOrgUnit.name");
					 adminOrg.setId(BOSUuid.read(adminOrgId));
					 adminOrg.setName(adminOrgName);
					 positionInfo.setAdminOrgUnit(adminOrg);
					 positionInfo.setHrOrgUnit(hrOrg);
				}
			}
			return positionInfo;
		} catch (BOSException e) {
			e.printStackTrace();
			return null;
		} catch (SQLException e) {
			e.printStackTrace();
			return null;
		}
		
	}

	private void initDeptF7() {
		HolidayBillInfo modelInfo = (HolidayBillInfo) this.model;
		prmtDept.setValue(modelInfo.getDept());
		prmtDept.setSubmittedValue(modelInfo.getDept());
	}

	private void getF7Dept() {
		Object value = prmtDept.getValue();
		AdminOrgUnitInfo adminOrg = new AdminOrgUnitInfo();
		if (prmtDept.getValue() != null && (!prmtDept.getValue().equals(""))) {
			if (value instanceof FullOrgUnitInfo) {
				adminOrg.setId(BOSUuid.read(((FullOrgUnitInfo) value).getId()
						.toString()));
				((HolidayBillInfo) model).setDept(adminOrg);
			}
		}
	}

	@Override
	public void saveModel() {
		getF7Dept();
		HolidayBillInfo billInfo = (HolidayBillInfo) model;
		if(!AYAttenBillStatusEnum.AUDIT_FAIL.equals(billInfo.getStatus()))
		{
			billInfo.setStatus(AYAttenBillStatusEnum.DRAFT);			
		}
		super.saveModel();
		//addMessage(javax.faces.application.FacesMessage.SEVERITY_INFO, "alert(11);debug;");
		this.outerScript="alert('该单据已经保存!');closeWindow();";
	}

	public PersonOTBalanceInfo sumPersonOTBalance(HolidayBillEntryInfo entry,
			PersonOTBalanceInfo oTBalanceInfo) {

		BigDecimal totalHour = entry.getTotalhour();
		if (totalHour == null) {
			totalHour = new BigDecimal("0");
		}
		BigDecimal totaluse = oTBalanceInfo.getTotaluse();
		if (totaluse == null) {
			totaluse = new BigDecimal("0");
		}
		oTBalanceInfo.setTotaluse(totaluse.add(totalHour));
		return oTBalanceInfo;
		// PersonOTBalanceFactory.getRemoteInstance().save(oTBalanceInfo);
	}

	public PersonOTBalanceCollection getPersonOTBalanceCollection(
			HolidayBillInfo billInfo) {
		if (billInfo == null) {
			return null;
		}
		EntityViewInfo evi = new EntityViewInfo();
		FilterInfo filter = new FilterInfo();
		if (billInfo.getApplier() != null) {
			filter.getFilterItems().add(
					new FilterItemInfo("person.id", billInfo.getApplier()
							.getId().toString(), CompareType.EQUALS));
		} else {
			return null;
		}
		evi.setFilter(filter);
		SelectorItemCollection sic = new SelectorItemCollection();
		sic.add("*");
		evi.setSelector(sic);
		try {
			return PersonOTBalanceFactory.getRemoteInstance()
					.getPersonOTBalanceCollection(evi);
		} catch (BOSException e) {
			e.printStackTrace();
			return null;
		}
	}
	
	public PersonOTBalanceCollection getPersonOTBalanceCollection(
			PersonInfo personInfo) {

		EntityViewInfo evi = new EntityViewInfo();
		FilterInfo filter = new FilterInfo();
		if (personInfo != null) {
			filter.getFilterItems().add(
					new FilterItemInfo("person.id", personInfo
							.getId().toString(), CompareType.EQUALS));
		} else {
			return null;
		}
		evi.setFilter(filter);
		SelectorItemCollection sic = new SelectorItemCollection();
		sic.add("*");
		evi.setSelector(sic);
		try {
			return PersonOTBalanceFactory.getRemoteInstance()
					.getPersonOTBalanceCollection(evi);
		} catch (BOSException e) {
			e.printStackTrace();
			return null;
		}
	}
	
    public boolean isDisabledByState(String param)
    {
    	boolean isDisabled = true;
    	Map componentRenderMap = new HashMap();  

        if(operateState == null || operateState.equals(OperateState.VIEW) || operateState.equals("amountApproved"))
            componentRenderMap.put("entryRowButton", Boolean.valueOf(true));
        else
            componentRenderMap.put("entryRowButton", Boolean.valueOf(false));
        isDisabled = componentRenderMap.get(param) != null ? ((Boolean)componentRenderMap.get(param)).booleanValue() : true;
        return isDisabled;    	
    }	
    
	public void holidayBillEntryBean_roadListModel(){
		holidayBillEntryBean.roadListModel();
	}

	public void submitModel() {
		getF7Dept();
		((HolidayBillInfo) model).setStatus(AYAttenBillStatusEnum.SUBMIT);

		super.submitModel();
		
	}

}
